package com.example.service.rabbit;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.controller.vo.AnotherVO;
import com.example.controller.vo.SendMsgVO;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author eatfi
 */
@Service
public class RabbitMqSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(SendMsgVO message) {
        AnotherVO anotherVO = new AnotherVO();
        anotherVO.setInfo("hello");
        rabbitTemplate.convertAndSend("test.queue", anotherVO);
    }

    public void sendToDirectExchange(SendMsgVO message) throws Exception {
       ObjectMapper objectMapper = new ObjectMapper();
       String json = objectMapper.writeValueAsString(message);
        rabbitTemplate.convertAndSend("direct.exchange1", "red", json);
    }
}
